package cn.stylefeng.guns.modular.common.service.impl;

import cn.stylefeng.guns.modular.common.mapper.CommonMapper;
import cn.stylefeng.guns.modular.common.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommonServiceImpl implements CommonService {
    @Autowired
    CommonMapper commonMapper;

    @Override
    public List<Map> getEqpTypeList() {
        return commonMapper.getEqpTypeList();
    }

    @Override
    public List<Map> getStation() {
        return commonMapper.getEqpStation();
    }

    @Override
    public List<Map> getOrgids() {
        return commonMapper.getOrgids();
    }

    @Override
    public List<Map> getItemList() {
        return commonMapper.getItemList();
    }

    @Override
    public List<Map> getRouteList() {
        return commonMapper.getRouteList();
    }

    @Override
    public List<Map> getTreeOrgids() {
        //获取最大一级组织id
        List<Map> parent1 = commonMapper.getParentOrgids("-1");
        for (Map map1 : parent1) {
            //获取第2级组织id
            List<Map> parent2 = commonMapper.getParentOrgids(map1.get("ORG_ID").toString());
            for (Map map2 : parent2) {
                //获取第3级组织id
                List<Map> parent3 = commonMapper.getParentOrgids(map2.get("ORG_ID").toString());
                map2.put("children", parent3);
            }
            map1.put("children", parent2);
        }
        return parent1;
    }
}
